#include <iostream>
#include <fstream>

using namespace std;

typedef struct node {
    int father;   //父节点
    int distance;   //到父节点的路长
    int out;        //出度
    int maxroad;    //到叶节点的路长
    int cut;       //切掉标志
} node, *pnode;

class dTree {
private:
    pnode tree;
    int BiggestDistance, numberofnode, sum, qhead, qend;
    int que[1000];
public:
    dTree(int n, int d, istream &in = cin) {        //构建与初始化树
        sum = 0;
        qhead = 0;
        qend = 0;
        BiggestDistance = d;
        numberofnode = n;
        tree = new node[n];
        tree[0].father = -1;
        tree[0].distance = 0;
        for (int i = 0; i < n; i++) {
            int NumOfSon, WeightOfRoad, num;
            in >> NumOfSon;
            tree[i].cut = 0;
            tree[i].out = NumOfSon;
            tree[i].maxroad = 0;
            for (int j = 0; j < NumOfSon; j++) {
                in >> num >> WeightOfRoad;
                tree[num].father = i;
                tree[num].distance = WeightOfRoad;
            }
        }
    }

    void push(int i) {              //入队列
        que[qend] = i;
        qend++;
    }

    int pop() {                  //出队列
        int temp = que[qhead++];
        return temp;
    }

    int cuttree() {                   //剪切
        for (int i = numberofnode - 1; i >= 0; i--) {
            if (tree[i].out == 0) {
                push(i);
            }
        }
        while (qhead != qend) {
            int temp = pop();
            int len = tree[temp].distance;
            int par = tree[temp].father;
            if (tree[par].cut == 0 && tree[temp].maxroad + len > BiggestDistance) {
                tree[par].cut = 1;
                cout << "[X]Node" << par << endl;
                par = tree[par].father;
                sum++;
            } else if (tree[temp].cut == 0 && tree[par].maxroad < tree[temp].maxroad + len) {
                tree[par].maxroad = tree[temp].maxroad + len;
            }
            if (--tree[par].out == 0)
                push(par);
        }
        return sum;
    }
};

int main() {
    int n, d;
    ifstream fin("1000_295.txt", ios::in);
    fin >> n >> d;
    dTree test(n, d, fin);
    fin.close();
    cout << test.cuttree();
    return 0;
}
